GDK W32: Preserve the target value for change_property()
authorРуслан Ижбулатов <lrn1986@gmail.com>
Sun, 26 Nov 2017 00:21:22 +0000 (00:21 +0000)
committerРуслан Ижбулатов <lrn1986@gmail.com>
Sat, 2 Dec 2017 10:38:39 +0000 (10:38 +0000)
We need to know the target atom value to know when we need to
do something with side-effects (since side-effects are expressed via
special target values). Previously, the code side-stepped that by looking
at the data type (which was rather unique for the one side-effect
target that we supported, signalled by the TARGETS target),
but for the DELETE target that seems to be no longer an option, hence the new
field to carry this information past the convert_selection() routine.

This prevents GDK from throwing a warning when trying to convert
a DELETE target, which has no format or data objects set.

The side-effects for the DELETE target happen earlier, in GTK layer.
By the point it gets to change_property(), it's a no-op.

https://bugzilla.gnome.org/show_bug.cgi?id=786509

gdk/win32/gdkdnd-win32.c
gdk/win32/gdkevents-win32.c
gdk/win32/gdkselection-win32.c
gdk/win32/gdkselection-win32.h

index 39e0b74906a75e69261c459621849279c9484da1..3e4b2e6f605eb121ce7502a59ad101f29769ce75 100644 (file)
@@ -1069,6 +1069,7 @@ idataobject_getdata (LPDATAOBJECT This,
         {
           target = frec->target;
           win32_sel->property_change_transmute = frec->transmute;
+          win32_sel->property_change_target_atom = frec->target;
         }
     }
 
@@ -2108,6 +2109,7 @@ _gdk_win32_dnd_do_dragdrop (void)
   /* Delete dnd selection after successful move */
   if (hr == DRAGDROP_S_DROP && dwEffect == DROPEFFECT_MOVE)
     {
+      GdkWin32Selection *win32_sel = _gdk_win32_selection_get ();
       GdkEvent tmp_event;
 
       memset (&tmp_event, 0, sizeof (tmp_event));
@@ -2116,6 +2118,7 @@ _gdk_win32_dnd_do_dragdrop (void)
       tmp_event.selection.send_event = FALSE;
       tmp_event.selection.selection = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND);
       tmp_event.selection.target = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE);
+      win32_sel->property_change_target_atom = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE);
       tmp_event.selection.property = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND);
       g_set_object (&tmp_event.selection.requestor, drag_ctx->source_window);
       tmp_event.selection.time = GDK_CURRENT_TIME; /* ??? */
index 601ca036c87ac2c4cc0266aefae655db52ae1140..4df73d56e63b88a0b6e62e1c997eac407421d1ed 100644 (file)
@@ -3821,6 +3821,7 @@ gdk_event_translate (MSG  *msg,
       property_change_data = g_new0 (STGMEDIUM, 1);
       win32_sel->property_change_data = property_change_data;
       win32_sel->property_change_format = msg->wParam;
+      win32_sel->property_change_target_atom = target;
 
       fixup_event (event);
       GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)"));
index 879b90d0b92e96e9a746779c0265f8cb0b3b7714..f53eae3e4b05e2176f3cf06a0ded4ff213da3af2 100644 (file)
@@ -357,6 +357,7 @@ gdk_win32_selection_init (GdkWin32Selection *win32_selection)
   win32_selection->dnd_data_object_target = NULL;
   win32_selection->property_change_format = 0;
   win32_selection->property_change_data = NULL;
+  win32_selection->property_change_target_atom = 0;
 
   atoms = g_array_sized_new (FALSE, TRUE, sizeof (GdkAtom), GDK_WIN32_ATOM_INDEX_LAST);
   g_array_set_size (atoms, GDK_WIN32_ATOM_INDEX_LAST);
@@ -894,6 +895,7 @@ send_targets_request (guint time)
   tmp_event.selection.property = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION);
   tmp_event.selection.requestor = owner;
   tmp_event.selection.time = time;
+  win32_sel->property_change_target_atom = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS);
 
   gdk_event_put (&tmp_event);
   win32_sel->targets_request_pending = TRUE;
@@ -2325,8 +2327,10 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel,
                                       gint               nelements)
 {
   if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION) &&
-      type == GDK_SELECTION_TYPE_ATOM) /* implies target == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS) */
+      win32_sel->property_change_target_atom == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS))
     {
+      win32_sel->property_change_target_atom = 0;
+
       if (win32_sel->clipboard_opened_for == INVALID_HANDLE_VALUE &&
           OpenClipboard (GDK_WINDOW_HWND (window)))
         {
@@ -2345,11 +2349,22 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel,
           open_clipboard_timeout (NULL);
         }
     }
+  else if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND) &&
+           mode == GDK_PROP_MODE_REPLACE &&
+           win32_sel->property_change_target_atom == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE))
+    {
+      /* no-op on Windows */
+      win32_sel->property_change_target_atom = 0;
+    }
   else if (mode == GDK_PROP_MODE_REPLACE &&
-           (win32_sel->property_change_data == NULL ||
+           (win32_sel->property_change_target_atom == 0 ||
+            win32_sel->property_change_data == NULL ||
             win32_sel->property_change_format == 0))
     {
-      g_warning ("Setting selection property with 0x%p == NULL or 0x%x == 0", win32_sel->property_change_data, win32_sel->property_change_format);
+      g_warning ("Setting selection property with 0x%p == NULL or 0x%x == 0 or 0x%p == 0",
+                 win32_sel->property_change_data,
+                 win32_sel->property_change_format,
+                 win32_sel->property_change_target_atom);
     }
   else if (mode == GDK_PROP_MODE_REPLACE &&
            win32_sel->property_change_data != NULL &&
@@ -2396,6 +2411,7 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel,
 
       win32_sel->property_change_format = 0;
       win32_sel->property_change_data = 0;
+      win32_sel->property_change_target_atom = 0;
     }
   else
     {
index 23dac737629e60925f267e01b88fd3409784e479..a71655460c9aefd96852d6dca4e1516016dce34f 100644 (file)
@@ -167,6 +167,8 @@ struct _GdkWin32Selection
   LPSTGMEDIUM       property_change_data;
   /* Carries the transmute field of the GdkSelTargetFormat from from idataobject_getdata() to property_change() */
   gboolean          property_change_transmute;
+  /* Carries the target atom from GDK_SELECTION_REQUEST issuer to property_change() */
+  GdkAtom           property_change_target_atom;
 
   /* TRUE when we are emptying the clipboard ourselves */
   gboolean          ignore_destroy_clipboard;